<template>
	<div class="givebox">
		<el-row>
			<el-tabs type="border-card">
				<el-tab-pane label="新入员工分配权限">
					<span style="color:crimson;float:right"> 当前有:{{emps.length}}名员工还未分配权限</span> 
					<el-table :data="emps" >
						<el-table-column prop="eid" label="id"></el-table-column>
						<el-table-column prop="ename" label="姓名"></el-table-column>
						<el-table-column prop="sex" label="性别">
							<template slot-scope="scope">
								<i v-if="scope.row.sex==0">男</i>
								<i v-else-if="scope.row.sex==1">女</i>
							</template>
						</el-table-column>
						<el-table-column prop="tel" label="电话"></el-table-column>
						<el-table-column prop="induct_date" label="入职日期"></el-table-column>
						<el-table-column label="操作">
							<template slot-scope="s">
					<!-- 利用作用域插槽，将当前行作为参数传给了方法del -->
					<!-- s.$index可以获取当前行数据的索引 -->
								<el-button type="success" @click="givepower(s.$index,s.row)">赋予权限</el-button>
							</template>
						</el-table-column>
					</el-table>
	
					<el-dialog title="给新员工添加权限" :visible.sync="dialogFormVisible">
						<el-form :model="form" label-width="100px">
							<el-form-item label="姓名:">
								<el-input v-model="form.ename" autocoplete="off" disabled></el-input>
							</el-form-item>
							<el-form-item label="请选择权限:">
								<el-select v-model="pickdept" placeholder="请选择" style="float:left" @change="checkpick">
									<el-option
									  v-for="item in rights"
									  :key="item.rid"
									  :label="item.rname"
									  :value="item.rid">
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item>
								<el-input v-model="form.eid" autocoplete="off" type="hidden"></el-input>
							</el-form-item>
							<el-button type="primary" @click="sureGive" :disabled="disable">确 定</el-button>
						</el-form>
					</el-dialog>
				</el-tab-pane>
			</el-tabs>
		</el-row>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				me:this.$parent.$parent.$parent.$parent.emp,
				emps:[],
				rights:[],
				pickdept:[],
				dialogFormVisible:false,
				form:{
						eid:0,
						ename:'',
				},
				disable:true,
				myindex:-1,
				value: '',
			}
		},
		created(){
			this.$axios.post("showright?deptno="+this.me.deptno+"").then(v=>{
				console.log(v)
				if(v.data){
					this.rights=v.data.rights;
					this.emps=v.data.emps;
				}else{
					this.$message.error("出错了！！")
					//alert("出错了！！");
				}
			}).catch(ex=>{
				this.$message.error("出错了！！"+ex)
				//alert("出错了！"+ex);
			})
		},
		methods:{
			givepower(index,row){
				this.dialogFormVisible=true;
				this.form={
					eid:row.eid,
					ename:row.ename,
				};
				this.myindex=index;
			},
			checkpick(){
				if(this.pickdept==''){
					this.disable=true;
				}else{
					this.disable=false;
					}
			},
			sureGive:function(){
				
					this.$axios.post("empaddrt?eid="+this.form.eid+"&rid="+this.pickdept+"").then(v=>{
						console.log(v)
						if(v.data){
							//alert("添加权限成功！！");
							this.$message.success("添加权限成功！！")
							this.dialogFormVisible=false;
						}else{
							this.$message.error("出错了！！")
							//alert("出错了！！");
						}
					}).catch(ex=>{
						this.$message.error("出错了！！"+ex)
						//alert("出错了！"+ex);
					})
					this.dialogFormVisible=false;
					this.pickemp="";
					this.form={
						eid:0,
						ename:'',
						}
						var tos=this.$parent.$parent.$parent.$parent.todos;
						tos.forEach((v)=>{
							if(v.type==22){
								if(v.num>1){
									v.num=v.num-1;
								}else{
									tos.splice(v,1);
								}					
							}
						})
					this.emps.splice(this.myindex,1);
						//确认修改
						this.myindex=-1;
					
			},
			
		}
	}
</script>

<style>

</style>
